using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class ElementHolderUI : MonoBehaviour
{
    [SerializeField] private ElementHolder _elementHolder;

    [SerializeField] private Image _fireIcon;
    [SerializeField] private Image _waterIcon;
    [SerializeField] private Image _grassIcon;
    [SerializeField] private Image _electricIcon;
    [SerializeField] private Image _iceIcon;
    [SerializeField] private Image _burningIcon;
    [SerializeField] private Image _frozenIcon;
    [SerializeField] private Image _quickenIcon;

    private void LateUpdate()
    {
        UpdateIcon(_fireIcon, "火");
        UpdateIcon(_waterIcon, "水");
        UpdateIcon(_grassIcon, "草");
        UpdateIcon(_electricIcon, "雷");
        UpdateIcon(_iceIcon, "冰");
        UpdateIcon(_burningIcon, "燃烧");
        UpdateIcon(_frozenIcon, "冻结");
        UpdateIcon(_quickenIcon, "激化");
    }

    private void UpdateIcon(Image icon, string auraName)
    {
        if (!icon)
        {
            return;
        }

        var aura = _elementHolder.GetElementAura(auraName);
        var text = icon.GetComponentInChildren<TextMeshProUGUI>();
        if (aura.Gauge > 0f)
        {
            icon.enabled = true;
            text.text = aura.Gauge.ToString("F1");
        }
        else
        {
            icon.enabled = false;
            text.text = string.Empty;
        }
    }
}